extends NodeState

@export var character:CharacterBody2D
@export var animated_sprite_2d:AnimatedSprite2D
@export var idel_state_interval:float = 5.0 
@onready var idle_state_timer:Timer = Timer.new()

var idle_state_timeout :bool = false

func _ready() -> void:
	if character.motionless:
		animated_sprite_2d.play("idle")
		return
	idle_state_timer.wait_time = idel_state_interval
	idle_state_timer.timeout.connect(on_idle_timeout)
	add_child(idle_state_timer)
	
func _on_process(_delta : float) -> void:
	pass


func _on_physics_process(_delta : float) -> void:
	pass


func _on_next_transitions() -> void:
	if idle_state_timeout:
		transition.emit("move")


func _on_enter() -> void:
	animated_sprite_2d.play("idle")
	idle_state_timeout = false
	idle_state_timer.start()

func _on_exit() -> void:
	animated_sprite_2d.stop()

func on_idle_timeout() -> void:
	idle_state_timeout = true
